package com.learn.project2.service.admin.feedback;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.learn.project2.bean.MarketFeedback;
import com.learn.project2.bean.MarketFeedbackExample;
import com.learn.project2.mapper.MarketFeedbackMapper;
import com.learn.project2.model.bo.admin.user.UserListBO;
import com.learn.project2.model.vo.admin.feedback.FeedbackListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wxy
 * @version 1.0
 * @description: 意见反馈
 * @date 2022-01-08 14:48
 */
@Service
//@CacheConfig(cacheNames = "marketFeedback")
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    MarketFeedbackMapper feedbackMapper;

    @Override
    public FeedbackListVO selectFeedback(Integer id, String username, UserListBO userListBO) {
        Integer limit = userListBO.getLimit();
        Integer page = userListBO.getPage();
        String sort = userListBO.getSort();
        String order = userListBO.getOrder();
        //使用分页插件
        PageHelper.startPage(page, limit);
        MarketFeedbackExample feedbackExample = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = feedbackExample.createCriteria();
        //username的模糊查询，id的精确查询
        if (username != null) {
            criteria.andUsernameLike("%" + username + "%");
        }
        if (id != null) {
            criteria.andIdEqualTo(id);
        }
        criteria.andDeletedEqualTo(false);                                                                                                                
        feedbackExample.setOrderByClause(sort + " " + order);
        List<MarketFeedback> list = feedbackMapper.selectByExample(feedbackExample);
        PageInfo<MarketFeedback> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();

        return FeedbackListVO.data(total,pages,limit,page,list);
    }
}
